package com.tianyadu.mmall.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;

/**
 * 权限
 *
 * @author xueyj
 * @date 2019-10-28 22:38
 */
@Data
@Entity
public class SysPermission implements Serializable {

    private static final long serialVersionUID = -7924133766758952368L;
    /**
     * id
     */
    @Id
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator = "uuid")
    private String id;

    /**
     * 上级权限
     */
    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pid")
    private SysPermission parent;

    /**
     * 权限名称
     */
    private String name;

    /**
     * 权限编码
     */
    private String code;

    /**
     * 优先级
     */
    private Integer priority;

    /**
     * url
     */
    private String url;


    /**
     * type：0代表菜单权限1代表按钮权限
     */
    private Integer type;

    /**
     * 图标
     */
    private String icon;

    /**
     * 子集权限
     */
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "parent")
    @OrderBy(value = "priority")
    private Set<SysPermission> children;

}